<?php
namespace app\madmin\controller;
use app\madmin\model\SystemLexiconModel;

/**
 * 词典控制器
 * @author  黄明杰 vx:HMJ125855
 * @version 20190101
 */
class SystemLexicon extends PublicBase{

	# 词典列表方法
    public function showList(){
        $SystemLexicon = new SystemLexiconModel;

        $Where = $this->getFormWhere();

        $Lists = $SystemLexicon->mList($Where, '*', config('CNF_LISTPAGE'));

        return $this->fetch('SystemLexicon/showList', [
            'Lists' => $Lists
        ]);
    }

    # 词典新增方法
    public function showAdd(){
        $SystemLexicon = new SystemLexiconModel;

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $SystemLexicon->mAdd($Param);

            $this->getLexiconList($Param['lexicon_name']);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            return $this->fetch('SystemLexicon/showAdd', [
                'Info' => Null
            ]);
        }
    }

    # 词典更新方法
    public function showEdit(){
        $SystemLexicon = new SystemLexiconModel;

        $ID = input('param.id');

        if(request()->isPost()){
            $Param = input('post.');

            $Back = $SystemLexicon->mEdit(['lexicon_id'=>$ID], $Param);

            $this->getLexiconList($Param['lexicon_name']);

            $this->ShowData($Back['code'], $Back['msgs'], $Back['urls']);
        }else{
            $Info = $SystemLexicon->mInfo(['lexicon_id'=>$ID]);

            if(empty($Info)){
                $this->ShowData(2, lang('XtCwCxCw'));
            }

            $Info['lexicon_content'] = arrayMultisort(unserialize($Info['lexicon_content']), 'content_sort');

            return $this->fetch('SystemLexicon/showAdd', [
                'Info' => $Info
            ]);
        }
    }

    # 词典删除方法
    public function showDel(){
    	if(request()->isPost()){
            $SystemLexicon = new SystemLexiconModel;

            $ID = input('post.id');

            $Back = $SystemLexicon->mDel(['lexicon_id'=>$ID]);

            $this->getLexiconList($Back['data']);

            $this->ShowData($Back['code'], $Back['msgs']);
        }
    }

}